/*
 * This file (ScriptVariable.java) is protected by the GNU GPL licence (v2). 
 * Please read the license.txt attached for further informations. 
 * 
 */
package org.algoristes.alkwarel.script;

/**
 * Structure to keep variables
 * 
 * @author Xavier Gouchet
 * 
 */
public class ScriptVariable {

	/** name of the variable */
	public String mName;
	/** value of the variable */
	public String mValue;
	/** depth at which the variable has been declared */
	private int mDepth;

	/**
	 * Default constructor
	 * 
	 * @param name
	 *            initial name of the variable
	 * @param value
	 *            initial value of the variable
	 * @param depth
	 *            depth at which the variable is declared
	 */
	public ScriptVariable(String name, String value, int depth) {
		mName = name;
		mValue = value;
		mDepth = depth;
	}

	/**
	 * @return the depth at which the variable has been declared
	 */
	public int getDepth() {
		return mDepth;
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return mValue;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		int hash;
		hash = mDepth * 37 + mName.hashCode();
		return hash;
	}

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(Object obj) {
		if (this == obj)
			return true;

		if ((obj == null) || (obj.getClass() != getClass()))
			return false;

		ScriptVariable var = (ScriptVariable) obj;

		// return ((var.mName.equals(mName)) && (var.mDepth == mDepth));
		return (var.mName.equals(mName));
	}
}
